﻿/*
 * 
 * liaison entre bipede.membres.Pied / Squelette et physic.Obstacle
 * 
 * 
 * */
package physic
{
	import bipede.membres.Pied;
	import bipede.membres.Squelette;
	import events.MoveEvent;
	import fab.geom.Segment;
	import flash.geom.Point;
	import flash.utils.Dictionary;
	import physic.Obstacle;
	
	public class Liaison
	{
		public var squelette:Squelette;
		public var pied:Pied;
		public var segment :Segment;
		public var obstacle:Obstacle;
		static public var liste:Array = new Array();
		
		public function Liaison( pied:Pied, obstacle:Obstacle, segment:Segment=null )
		{
			this.pied = pied;
			this.squelette = pied.squelette;
			this.obstacle = obstacle;
			this.segment = segment;
			liste.push( this );
		}
		public function obstacle_moving( deplacement:Point )
		{
			squelette.move( new MoveEvent( MoveEvent.MOVING, deplacement, null, true ) );
			//squelette.move( new MoveEvent( MoveEvent.MOVING, deplacement, null, true ) );
		}
		static public function getPieds( obstacle:Obstacle ):Array
		{
			var a:Array = new Array();
			for each( var liaison:Liaison in liste )
			{
				if ( liaison.obstacle == obstacle ) a.push( liaison );
			}
			return a;
		}		
		//static public function getSquelettes( obstacle:Obstacle ):Array
		//{
			//var a:Array = new Array();
			//for each( var liaison:Liaison in liste )
			//{
				//if ( liaison.obstacle == obstacle ) a.push( liaison );
			//}
			//return a;
		//}
		static public function getObstacles( squelette:Squelette ):Array
		{
			var a:Array = new Array();
			for each( var liaison:Liaison in liste )
			{
				if ( liaison.squelette == squelette ) a.push( liaison );
			}
			return a;
		}
		static public function getObstaclesByPied( pied:Pied ):Array
		{
			var a:Array = new Array();
			for each( var liaison:Liaison in liste )
			{
				if ( liaison.pied == pied ) a.push( liaison );
			}
			return a;
		}		
		static public function destroy( pied:Pied, obstacle:Obstacle ):void
		{
			for each( var liaison:Liaison in liste ) if ( liaison.pied == pied && liaison.obstacle == obstacle ) liste.splice( liste.indexOf( liaison ), 1 );
		}		
		public function toString():String
		{
			return "Liaison " + pied + "de " + squelette + " sur " + obstacle;
		}			
	}	
}